﻿using MiniExcelLibs;
using MiniExcelLibs.Attributes;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace YellowJExcel.Tests
{
    class Program
    {
        static void Main(string[] args)
        {
            GenerateData(10000);
            // 简单使用
            var list = YellowJExcel.Read<User>("E:\\测试/mini.xlsx");
            //YellowJExcel.Write("E:\\测试/output.xlsx", list);

            // 高级配置
            var config = new ExcelConfig<User>
            {
                SheetName = "用户数据",
                ExcludedColumns = new HashSet<string> { "Password" },
                HiddenColumns = new HashSet<string> { "Id" },
                ColumnOrder = new List<string> { "Name", "Age", "Email" },
                ColumnColors = new Dictionary<string, string>
                {
                    ["Email"] = "#F0F8FF"
                }
            };

            config.ConditionalRules.Add((user => user.Age < 18, "#FFB6C6"));

            YellowJExcel.Write("E:\\测试/output.xlsx", list, config);
        }

        static List<User> GenerateData(int count)
        {
            //var list = YellowJExcel.Read<User>("E:\\测试/mini.xlsx");

            var users = new List<User>();
            Random random = new Random();

            for (int i = 0; i < count; i++)
            {
                users.Add(new User
                {
                    Id = i + 1,
                    Name = $"用户{i + 1}",
                    Age = random.Next(12, 60),
                    IsStudent = random.Next(0, 2) == 0
                });
            }
            YellowJExcel.Write("E:\\测试/mini.xlsx", users);
            return users;
        }
    }

    public class User
    {
        public int Id { get; set; }
        [ExcelColumnName("姓名")]
        public string Name { get; set; }
        [ExcelColumnName("年龄")]
        public int Age { get; set; }
        public bool IsStudent { get; set; }
    }
}